clear all
set mem 50m
* cd "..."
use "DATA_COMPILED_ATOP_20151118.dta"
set more off 

label var interaction "Troops $\times$ Troops Spatial Mean"
label var meanregionalallies "Host-State Allies (Spatial Mean)"
label var meanregionalusallies "US Allies (Spatial Mean)"

xtset ccode year
* Summary Statistics from Model 1 
xtpcse defenseburden l.lntroops l.lntroops_spmean l.interaction l.spatial_lag l.polity l.growth ///
	l.lntpop l.IMR l.threat_environment war movav3 borderstates civilwar ///
	l.meanregionalallies l.meanregionalusallies if year<2004 , corr(ar1) pairwise 	
	

postutil clear
tempname sumstats
postfile `sumstats' str50 name N mean std min max using sumstats, replace
foreach var of varlist defenseburden l.lntroops l.lntroops_spmean l.interaction l.meanregionalallies l.meanregionalusallies l.spatial_lag l.polity l.growth l.lntpop l.IMR war civilwar movav3 l.threat_environment borderstates {
sum `var' if e(sample), d
scalar mean = r(mean)
scalar std = r(sd)
scalar min = r(min)
scalar max = r(max)
post `sumstats' ("`:variable label `var''") (r(N)) (mean) (std) (min) (max)
scalar drop _all
}
postclose `sumstats'
clear
use sumstats


replace name = "Defense Burden" in 1
replace name = "ln (Troops)" in 2
replace name = "ln (Troops) Spatial Mean" in 3
replace name = "ln (Troops) $\times$ ln (Troops) Spatial Mean" in 4
replace name = "Host-State Allies (Spatial Mean)" in 5
replace name = "US Allies (Spatial Mean)" in 6
replace name = "Spatial Lag" in 7
replace name = "Polity" in 8
replace name = "Growth" in 9
replace name = "ln (Total Population)" in 10
replace name = "Infant Mortality Rate" in 11
replace name = "Interstate War" in 12
replace name = "Civil War" in 13
replace name = "MIDs" in 14
replace name = "Threat Environment" in 15
replace name = "\#Border States" in 16

format mean std min max %9.3fc

rename name Name 
rename mean Mean
rename std Std
rename min Min
rename max Max

listtex Name N Mean Std Min Max using table_sumstats_20150524.tex, rstyle(tabular) replace ///
delimiter("&") headlines("\begin{tabular}{l c c c c c}" "\hline\hline" "Variable Name & N & Mean & Std. & Min & Max \\ \hline" ) footlines("\hline\hline" "\end{tabular}") type
